using System;
using System.Collections.Generic;
using System.Text;

namespace Pampa.WebControls
{
    public enum ValidationType
    {
        Required = 1,
        Range = 2,
        Pattern = 3,
        Occurs = 4,
        Custom = 5
    }

    public class Validation
    {
        private ValidationType type;
        private string arguments;
        private string message;

        public ValidationType Type
        {
            get { return type; }
            set { type = value; }
        }

        public string Arguments
        {
            get { return arguments; }
            set { arguments = value; }
        }

        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        public Validation(ValidationType type, string arguments, string message)
        {
            this.Type = type;
            this.Arguments = arguments;
            this.Message = message;
        }

        public static Validation GetRangeValidation(string dataType, string minimunValue, string maximunValue, bool graterOrEqual, bool lessOrEqual, string errorMsg)
        {
            // referencia a la validacion
            string arguments = dataType;

            // toma el formato de fecha de la maquina
            if (dataType == "Date")
                arguments += "{" + Pampa.Common.Utils.Formats.DateFormat + "}";

            // toma el formato de decimales de la maquina
            if (dataType == "Double")
            {
                arguments += "{" + Pampa.Common.Utils.Formats.DecimalSeparator + "}";

                // el minimo y el maximo se deben pasar siempre con punto
                if (!String.IsNullOrEmpty(minimunValue))
                    minimunValue = minimunValue.Replace(".", Pampa.Common.Utils.Formats.DecimalSeparator);

                if (!String.IsNullOrEmpty(maximunValue))
                    maximunValue = maximunValue.Replace(".", Pampa.Common.Utils.Formats.DecimalSeparator);
            }

            if (!(String.IsNullOrEmpty(minimunValue)) || !(String.IsNullOrEmpty(maximunValue)))
            {
                arguments += "#";

                if (String.IsNullOrEmpty(minimunValue))
                {
                    arguments += "(-";
                }
                else
                {
                    if (graterOrEqual)
                        arguments += "[" + minimunValue;
                    else
                        arguments += "(" + minimunValue;
                }

                if (String.IsNullOrEmpty(maximunValue))
                {
                    arguments += ";+)";
                }
                else
                {
                    if (lessOrEqual)
                        arguments += ";" + maximunValue + "]";
                    else
                        arguments += ";" + maximunValue + ")";
                }
            }

            return new Validation(ValidationType.Range, arguments, errorMsg);
        }
    }
}
